package com.tutu.controller.backend;

import com.tutu.common.DataTableFactory;
import com.tutu.controller.common.CommonController;
import com.tutu.service.AlarmMessageService;
import com.tutu.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 预警消息管理
 */
@Controller
@RequestMapping(value = "backend/alarmMessage")
public class AlarmMessageController extends CommonController {

    @Autowired
    AlarmMessageService alarmMessageService;

    @RequestMapping(value = "/index")
    public String index() {
        return "backend/alarmMessage/list";
    }

    @RequestMapping("/list")
    public void list(HttpServletResponse response, Integer companyId, String deviceCode, Integer type, String startTime, String endTime, String keyWord, Integer draw, Integer start, Integer length) {
        int pageNum = getPageNum(start, length);

        Map<String, Object> result = DataTableFactory.fitting(draw, alarmMessageService.pageByParams(companyId, deviceCode, type, startTime, endTime, keyWord, pageNum, length));

        WebUtil.printJson(response, result);
    }

    @RequestMapping("/sync")
    @ResponseBody
    public Map<String, Object> sync(HttpServletRequest request) {
        return alarmMessageService.syncData(request);
    }

    @RequestMapping("/alarmMessageStatic")
    @ResponseBody
    public Map<String, Object> alarmMessageStatic(HttpServletRequest request, Integer count) {
        return alarmMessageService.alarmMessageStatic(request, count);
    }
}
